package com.chen.blue.controller.admin.system;


import com.chen.blue.domain.delete.system.DeptDelete;
import com.chen.blue.domain.delete.system.PostDelete;
import com.chen.blue.domain.dto.system.DeptDto;
import com.chen.blue.domain.dto.system.PostDto;
import com.chen.blue.domain.dto.system.update.DeptDtoEdit;
import com.chen.blue.domain.dto.system.update.PostDtoEdit;
import com.chen.blue.domain.query.system.DeptQuery;
import com.chen.blue.domain.query.system.PostQuery;
import com.chen.blue.domain.vo.system.PostVo;
import com.chen.blue.exception.e.DtoNullException;
import com.chen.blue.result.DataResult;
import com.chen.blue.result.R;
import com.chen.blue.service.system.IPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 岗位信息表 前端控制器
 * </p>
 *
 * @author CLT
 * @since 2024-05-10
 */
@Api(tags = "岗位模块")
@Validated
@RestController
@RequestMapping("/post")
public class PostController {

    @Resource
    private IPostService iPostService;

    @ApiOperation(value = "岗位添加", notes = "岗位添加")
    @PostMapping("/add")
    public R add(@RequestBody @Valid PostDto postDto) throws DtoNullException {

        return iPostService.addPost(postDto) ? R.success() : R.faild();

    }

    @ApiOperation(value = "岗位删除", notes = "岗位删除")
    @DeleteMapping("/delete")
    public R delete(@RequestBody PostDelete postDelete) throws DtoNullException {

        return iPostService.deletePost(postDelete) ? R.success() : R.faild();

    }

    @ApiOperation(value = "岗位修改", notes = "岗位修改")
    @PutMapping("/edit")
    public R updateById(@RequestBody @Valid PostDtoEdit postDtoEdit) throws DtoNullException {

        return iPostService.updatePostById(postDtoEdit) ? R.success() : R.faild();

    }

    @ApiOperation(value = "多条件查询岗位", notes = "多条件查询岗位")
    @PostMapping("/query")
    public R<DataResult<List<PostVo>>> query(@RequestBody PostQuery postQuery) throws DtoNullException {

        return R.success(iPostService.queryPost(postQuery));

    }

    @ApiOperation(value = "ID查询岗位", notes = "ID查询岗位")
    @GetMapping("/queryById/{id}")
    public R<DataResult<PostVo>> queryById(@PathVariable("id") Long id) throws DtoNullException {

        return R.success(iPostService.queryPostById(id));

    }

}

